-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[issue #914] _P053_PMSx003 Dust Sensor looses sync #976
Conversation
TD-er
commented
Feb 28, 2018
- Use peek instead of read, to make sure a complete packet is in the buffer.
- Flush buffer after processing a packet.
- Increased software serial buffer to the size of 3 packets.
- Peek (+ read garbage) 10 times per second to get the buffer in sync to start with start byte of packet.
- Decent delete + clean up of software serial allocation when changing settings (prevent memory leak)
- Move log String allocation to inside scope of function, not permanent allocated.
- Split into separate functions to make it better readable.
- Use peek instead of read, to make sure a complete packet is in the buffer. - Flush buffer after processing a packet. - Increased software serial buffer to the size of 3 packets. - Peek (+ read garbage) 10 times per second to get the buffer in sync to start with start byte of packet. - Decent delete + clean up of software serial allocation when changing settings (prevent memory leak) - Move log String allocation to inside scope of function, not permanent allocated. - Split into separate functions to make it better readable.
It is better to check also if dummy (marker) is exactly 0x424D, if not we don't need to try calculate checksum. Looks like problem was because always take 2 bytes from buffer and datagram has even bytes so it is impossible to find sync if miss one byte. |
That's a good suggestion. (it was past 2am) |
Quickly commit + merge is never a good idea when some visitors arrive... Fixed now.
OK, test begins. |
@micropet OK to merge it? |
Unfortunately, no. There were about 60 minutes of data delivered. |
But it is not worse than before? |
Yes you are right. This version also runs longer than the old version. |
I've been running this version on an ESP32 and STMF4 board for many months now. She has never failed. Maybe it gives you an idea. #include "serialReadPMValue.h" int length = serialRead(Serial1,receiveDat,receiveDatIndex,5); //change the serial port:Serial1,Serial2.. if(length&&checkSum) |